passwordentry: Implement GtkAccessible
authorMatthias Clasen <mclasen@redhat.com>
Tue, 13 Oct 2020 01:33:55 +0000 (21:33 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 13 Oct 2020 01:45:48 +0000 (21:45 -0400)
This copies what was done for GtkEntry: get
the focused state from the GtkText within.

gtk/gtkpasswordentry.c

index ec8d08b1192d7567b50f816d2af30ef2bd587636..e6658ecf2e40346e06257c1871d5136056a9009e 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "gtkpasswordentryprivate.h"
 
+#include "gtkaccessibleprivate.h"
 #include "gtktextprivate.h"
 #include "gtkeditable.h"
 #include "gtkeventcontrollerkey.h"
@@ -105,8 +106,10 @@ enum {
 static GParamSpec *props[NUM_PROPERTIES] = { NULL, };
 
 static void gtk_password_entry_editable_init (GtkEditableInterface *iface);
+static void gtk_password_entry_accessible_init (GtkAccessibleInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkPasswordEntry, gtk_password_entry, GTK_TYPE_WIDGET,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE, gtk_password_entry_accessible_init)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_password_entry_editable_init))
 
 static void
@@ -487,6 +490,31 @@ gtk_password_entry_editable_init (GtkEditableInterface *iface)
   iface->get_delegate = gtk_password_entry_get_delegate;
 }
 
+static gboolean
+gtk_password_entry_accessible_get_platform_state (GtkAccessible              *self,
+                                                  GtkAccessiblePlatformState  state)
+{
+  GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (self);
+
+  switch (state)
+    {
+    case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE:
+      return gtk_widget_get_focusable (GTK_WIDGET (entry->entry));
+    case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
+      return gtk_widget_has_focus (GTK_WIDGET (entry->entry));
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+static void
+gtk_password_entry_accessible_init (GtkAccessibleInterface *iface)
+{
+  GtkAccessibleInterface *parent_iface = g_type_interface_peek_parent (iface);
+  iface->get_at_context = parent_iface->get_at_context;
+  iface->get_platform_state = gtk_password_entry_accessible_get_platform_state;
+}
+
 GtkText *
 gtk_password_entry_get_text_widget (GtkPasswordEntry *entry)
 {